<template>
    <div>
        <!--<span style="margin: 5px 0 5px 5px;font-size: 14px;">{{block.name}}</span>-->
        <div class="block-column">
            <div v-for="(entry, index) of block.blockEntry" class="entry-container">
                <div class="entry">
                    <img :src="getImagePath(index)" style="height: 37vw;" @tap="handleImageClick(index)" />
                    <div v-if="entry.type == 1" class="entry-content">
                        <h4>{{entry.product.name}}</h4>
                        <div style="display: flex; flex-direction: row; justify-content: space-between; align-items: center; width: 100%">
                            <span>￥{{entry.product.price / 100}}</span>
                            <div class="action-button red biyao" @tap="handleEntryClick(index)">立即购买</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>

import { apiDomain, fetchDomain } from 'assets/js/Lib'

export default {
    data() {
        return {
            
        }
    },
    computed: {
        webApiDomain: function () {
            return apiDomain;
        }
    },
    components: {

    },
    props: {
        block: {
            type: Object,
            default: {}
        },
    },
    watch: {
    },
    //实例初始化最之前，无法获取到data里的数据
    beforeCreate() {
    },
    //在挂载开始之前被调用
    beforeMount() {
    },
    //已成功挂载，相当ready()
    mounted() {
        console.log('this.block', this.block);
    },
    //相关操作事件
    methods: {
      openPage: function (url) {
        if (!url) {
          return;
        }
        let pageConfig = {
          "id": url,
          "url": url,
          show: {
            autoShow: true
          },
          waiting: {
            title: '加载中...'
          }
        }

        mui.openWindow(pageConfig)
      },
        handleEntryClick(i) {
            console.log('handleEntryClick', i);
            if (!this.block.blockEntry[i]) {
                return;
            }
            let type = this.block.blockEntry[i].type;
            if (type == 1) {
                this.openPage(`${fetchDomain}/views/product.html?isBiYao=false&id=${this.block.blockEntry[i].product_id}`);
            } else if (type == 2) {
                this.openPage(this.block.blockEntry[i].url);
            }
        },
        handleImageClick(i) {
            if (this.block.blockEntry[i].type == 2) {
                this.openPage(this.block.blockEntry[i].url);
            }
        },
        getImagePath(i) {
            let type = this.block.blockEntry[i].type;
            if (type == 1) {
                let file = this.block.blockEntry[i].product.file;
                return `${apiDomain}/public/uploads/${file.savepath}${file.savename}`;
            } else if (type == 2) {
                let file = this.block.blockEntry[i].file;
                return `${apiDomain}/public/uploads/${file.savepath}${file.savename}`;
            }
        }
    }
}
</script>

<style scoped lang="less">
    .block-column {
        width: 100%;

        :last-child {
            border-bottom: 0 !important;
        }

        .entry-container {
            /*padding: 15px 0;*/
            border-bottom: 1px solid #eeeeee;
            height: 37vw;

            .entry {
                display: flex;
                flex-direction: column;
                align-items: center;
                width: 100vw;

                .entry-content {
                    display: block;
                    width: 100%;
                }
            }
        }
    }

    .action-button {
        padding: 5px;
        color: #ffffff;
        font-size: .36875rem;
        float: left;
        text-align: center;
    }

    .action-button.red {
        background-color: #f23030;
    }
</style>
